From: Florian Müllner Date: Thu, 27 Nov 2025 10:28:23 +0000 (+0100) Subject: animationUtils: Use easeAsync() for wiggle X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~44^2~29 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=fdadbb7a5a23d3efa26ab8be053c7d54715ec999;p=gnome-shell.git animationUtils: Use easeAsync() for wiggle The wiggle animation consists of 3 chained animations. This is expressed a lot nicer with a series of async calls than nested callbacks. Part-of: --- diff --git a/js/misc/animationUtils.js b/js/misc/animationUtils.js index cf6889609..44d6e2fff 100644 --- a/js/misc/animationUtils.js +++ b/js/misc/animationUtils.js @@ -2,6 +2,7 @@ import St from 'gi://St'; import Clutter from 'gi://Clutter'; import * as Params from './params.js'; +import {logErrorUnlessCancelled} from './errorUtils.js'; const SCROLL_TIME = 100; @@ -83,7 +84,7 @@ export function ensureActorVisibleInScrollView(scrollView, actor) { * @param {number} params.duration - the amount of time to move the actor per-wiggle * @param {number} params.wiggleCount - the number of times to wiggle the actor */ -export function wiggle(actor, params) { +export async function wiggle(actor, params) { if (!St.Settings.get().enable_animations) return; @@ -94,28 +95,30 @@ export function wiggle(actor, params) { }); actor.translation_x = 0; - // Accelerate before wiggling - actor.ease({ - translation_x: -params.offset, - duration: params.duration, - mode: Clutter.AnimationMode.EASE_OUT_QUAD, - onComplete: () => { - // Wiggle - actor.ease({ - translation_x: params.offset, - duration: params.duration, - mode: Clutter.AnimationMode.LINEAR, - repeatCount: params.wiggleCount, - autoReverse: true, - onComplete: () => { - // Decelerate and return to the original position - actor.ease({ - translation_x: 0, - duration: params.duration, - mode: Clutter.AnimationMode.EASE_IN_QUAD, - }); - }, - }); - }, - }); + try { + // Accelerate before wiggling + await actor.easeAsync({ + translation_x: -params.offset, + duration: params.duration, + mode: Clutter.AnimationMode.EASE_OUT_QUAD, + }); + + // Wiggle + await actor.easeAsync({ + translation_x: params.offset, + duration: params.duration, + mode: Clutter.AnimationMode.LINEAR, + repeatCount: params.wiggleCount, + autoReverse: true, + }); + + // Decelerate and return to the original position + await actor.easeAsync({ + translation_x: 0, + duration: params.duration, + mode: Clutter.AnimationMode.EASE_IN_QUAD, + }); + } catch (e) { + logErrorUnlessCancelled(e); + } }